import RandomUtil from '@/RandomUtil';
import UnitStateUtil from '@/UnitStateUtil';
import EffectCommon from 'code/Core/Common/EffectCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import TalentBase from 'code/Scripts/Abilities/base/TalentBase';

const desc = '攻击时有|cff1fff4425%|r的机率附加目标最大生命|cff1fff4465%|r的伤害，并且对精英单位造成的伤害提升|cff1fff4425%|r|n觉醒后触发机率增加至|cff1fff4450%|r,对精英伤害提升至|cff1fff4450%|r';
const art = 'ReplaceableTextures\\CommandButtons\\BTNSpiritOfVengeance.blp';
const config: TalentConfigModel = {
    id: 'tanlent_execute',
    name: '处决',
    art,
    desc,
    buffType: {
        id: 'buff_t_execute',
        name: '处决',
        ubertip: desc,
        art,
        attribute: {
            精英伤害增强: 0.25,
        },
    },
    buffTypePlus: {
        id: 'buff_t_execute_plus',
        name: '处决[觉醒]',
        ubertip: `攻击时有|cff1fff4450%|r的机率附加目标最大生命|cff1fff4465%|r的伤害，并且对精英单位造成的伤害提升|cff1fff4450%|r`,
        art,
        attribute: {
            精英伤害增强: 0.5,
        },
    },
};

/**
 * 处决天赋
 * 攻击时有25%的机率附加目标最大生命65%的攻击伤害，对精英伤害提升25%
 * 觉醒： 机率提升到50%，且对精英伤害提升至50%
 */
export default class TalentExecute extends TalentBase {
    static instance: TalentBase;
    constructor(p?: TalentConfigModel) {
        super(p);
        TalentExecute.instance = this;
        this.setTalentConfig(config);
        EventManager.onBeforApplyAttack(this.onUnitAttacked);
    }
    onUnitAttacked(d: DamageEventData) {
        if (UnitCommon.是否精英单位(d.target)) return;
        let { unEffect, normal, plus } = TalentExecute.instance.talentUnEffect(d.source);
        if (unEffect) return;
        let r = RandomUtil.randomPercent();
        if (r > (plus ? 0.5 : 0.25)) {
            return;
        }
        let dmg = UnitStateUtil.getMaxLife(d.target) * 0.65;
        d.initDamage += dmg;
        EffectCommon.delyRemove(AddSpecialEffectTarget('Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl', d.target, 'origin'), 1);
        PlaySound('Units\\NightElf\\HeroWarden\\WardenDeath1.wav');
    }
}
